package oop.a01oop.a02Polymorphism;

public class Person {
    private int age;
    private String name;

    public Person() {
    }

    public Person(int age, String name) {
        this.age = age;
        this.name = name;
    }


    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    public void keepPet(Animal a ,String something){
        if (a instanceof Dog dog){
            System.out.println("年纪为"+getAge()+"的"+getName()+"养了一只"+dog.getColor()+"色"+dog.getAge()+"岁的狗");
            dog.eat(something);
        }else if (a instanceof Cat cat){
            System.out.println("年纪为"+getAge()+"的"+getName()+"养了一只"+cat.getColor()+"色"+cat.getAge()+"岁的猫");
            cat.eat(something);
        }

    }


}
